var api = require('../../util/api.js');
Page({
    data: {

    },
    onLoad: function (options) {
        var _this = this;
        let chain = api.chain();
        _this.setData({
            showAdd: chain.mode == 'EDIT' && api.hasPerm('lhjd:wx:06:06:03')
        });
        api.get(`${api.ip}lhjd/sgdwpfb/list`, {
            examineId: chain.examineId,
            userId: chain.userId,
            unitId: chain.judgeId
        }).then(res => {
            if (res.rows.length == 0) {
                this.setData({
                    hasData: false
                })
            } else {
                _this.setData({
                    hasData: true,
                    dataList: res.rows
                })
            }
        })
    },
    goAdd() {
        let chain = api.chain();
        let examineId = chain.examineId;
        let userId = chain.userId;
        let userName = chain.userName;
        wx.navigateTo({
            url: `./edit?examineId=${examineId}&userId=${userId}&userName=${userName}`
        })
    },
    longPress(e) {
        let mode = api.chain().mode;
        if(mode != 'EDIT' || !api.hasPerm('lhjd:wx:06:06:02')){
            return;
        }
        var id = e.currentTarget.dataset.id;
        wx.showActionSheet({
            itemList: ['编辑'],
            success: function (res) {
                if (res.tapIndex == 0) {
                    wx.navigateTo({
                        url: `./edit?id=${id}`
                    });
                }
            },
            fail: function (res) {
                console.log(res.errMsg)
            }
        })
    },
    onPullDownRefresh() {
        this.setData({
            page: api.page(5),
            dataList: [],
        });
        this.onLoad();
    },
})